<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>

    </style>
</head>
<body>
    <input type="text" name="" id="">
    <button>按钮</button>
    <ul class="fruitList">
        <li>香蕉</li>
        <li>苹果</li>
        <li>鸭梨</li>
    </ul>
    <script>
        let btn=document.querySelector("button")
        let ul=document.querySelector('ul')
        let inp=document.querySelector('input')
        let list=document.querySelectorAll('.fruitList li')
        btn.onclick=function(){
            // console.log(inp.value)
            let li =document.createElement('li');
            let txt=document.createTextNode(inp.value)
            ul.appendChild(li)
            li.appendChild(txt)
        }
        // for (let i in list){
        //     list[i].onclick=function(){
        //         ul.removeChild(this)
        //     }
        // }
        ul.onclick=function(e){
            // console.log(e.target)
            // 目标指的li，e.target指向的事件捕获最底层的项目
            ul.removeChild(e.target)
        }
    </script>
</body>
</html>